package cn.edu.scnu.springbootcinema.mapper;

import cn.edu.scnu.springbootcinema.entity.Movie;
import cn.edu.scnu.springbootcinema.entity.RegionMovieCount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MovieMapper extends BaseMapper<Movie> {

    @Select("select region,count(view_count) as count from movies\n" +
            "        group by region")
    List<RegionMovieCount> getRegionMovieCount();

    @Select("select distinct m.* from movies m,movie_actors ma,actors a " +
            "where m.id=ma.movie_id and ma.actor_id=a.id" +
            " and (concat(a.first_name,a.last_name)" +
            " like concat('%',#{query},'%') " +
            "or m.title like concat('%',#{query},'%') or m.director like concat('%',#{query},'%'))")
    List<Movie> searchByQuery(String query);
}